import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter, FormatStrFormatter

root = ET.parse("D:\\StarCraft\\bwapi-data\\logs\\g.xml").getroot()
generations = root.findall("generation")

avg_fitness = []

for gen in generations:
	avg_fitness.append(0)
	i = 0
	for g in gen.findall("genome"):
		f = float(g.find("fitness").get("value"))
		avg_fitness[len(avg_fitness)-1] += f
		i += 1
	avg_fitness[len(avg_fitness)-1] = avg_fitness[len(avg_fitness)-1]/i

plt.xlabel("generations")
plt.ylabel("fitness")
plt.subplot(111).xaxis.set_major_formatter(FormatStrFormatter('%0.0f'))
plt.axis([0,40,0.54,0.72])
plt.title("avarage fitness")
plt.plot(avg_fitness)
plt.show()